package com.aaa.service.impl;

import com.aaa.dao.DeptDao;
import com.aaa.entity.Dept;
import com.aaa.entity.PageSort;
import com.aaa.entity.Userinfo;
import com.aaa.service.DeptService;
import com.aaa.util.Enum01;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service


public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptDao deptDao;

    /**
    * @Author: WTH
    * @Description: 查询
    * @Date:2022-07-01 09:51
    * @Params: 
    */
    @Override
    public Page<Dept> selectDept(PageSort pageSort) {
        Page<Dept> page= PageHelper.startPage(pageSort.getPage(),pageSort.getLimit());
        List<Dept> depts = deptDao.selectDept(pageSort);
        Page page1= (Page) depts;
        return page1;
    }

    @Override
    public List<Dept> selectDeptFirst() {
        return deptDao.selectDeptFirst();
    }

    /**
    * @Author: WTH
    * @Description: 新增
    * @Date:2022-07-01 09:51
    * @Params: 
    */
    @Override
    public Enum01 addDept(Dept dept) {
            int i = deptDao.addDept(dept);
            if(i>0){
                return Enum01.SUCCESS;
            }else{
                return Enum01.FAIL;
            }
    }

    /**
    * @Author: WTH
    * @Description: 批量删除
    * @Date:2022-07-01 09:51
    * @Params: 
    */
    @Override
    public boolean deleteDept(String dept_id) {
        int i = deptDao.deleteDept(dept_id);
        if(i>0){
            return true;
        }
        return false;
    }

    /**
    * @Author: WTH
    * @Description: 修改
    * @Date:2022-07-01 09:51
    * @Params: 
    */
    @Override
    public Enum01 updateDept(Dept dept) {
        int i = deptDao.updateDept(dept);
        if(i>0){
            return Enum01.SUCCESS;
        }else{
            return Enum01.FAIL;
        }
    }

    /**
    * @Author: WTH
    * @Description: 单条删除，删除校验
    * @Date:2022-07-01 09:58
    * @Params: 
    */
    @Override
    public Enum01 deleteDeptByid(Integer dept_id) {
        List<Userinfo> userinfos = deptDao.selectUserinfoByid(dept_id);
        if(userinfos!=null && userinfos.size()>0){
            return Enum01.DELETE_DEPT;
        }else{
            int i = deptDao.deleteDeptByid(dept_id);
            if(i>0){
                return Enum01.SUCCESS;
            }else{
                return Enum01.FAIL;
            }
        }
    }

    /**
    * @Author: WTH
    * @Description: 部门名称重复性校验
    * @Date:2022-07-08 15:20
    * @Params:  * @param null
    * @return:
    */
    @Override
    public boolean selectDeptName(Dept dept_name) {
        List<Dept> depts = deptDao.selectDeptByname(dept_name);
        if(depts!=null && depts.size()>0){
            return true;
        }
        return false;
    }

}
